<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>测试接口</title>
<script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>
<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
</head>
<body>
	<div id="box">
		<textarea v-model="service" placeholder="请输入域名" cols="120" rows="1"></textarea>
		<br>
		<textarea v-model="sessionId" placeholder="sessionId" cols="120" rows="1"></textarea>
		<br>
		<input type="button" @click="post()" value="Post">
		<input type="button" @click="get()" value="Get">
		<input type="number" v-model="number">
		<input type="button" @click="go" :value="'Post:' + number + '次'">
		<br><br>
		<textarea v-model="url" placeholder="请输入地址" cols="120" rows="1"></textarea>
		<br><br>
		<textarea v-model="text" placeholder="请输入JSON" cols="120" rows="30"></textarea>
		<hr>
		<div v-for="(msg , index) in msgList">
			<pre v-html="msg"></pre>
			<hr>
		</div>
	</div>
	<script type="text/javascript">
		// 教程 http://www.runoob.com/vue2/vuejs-ajax.html
		window.onload = function() {
			var fn = {
					go : function() {
						for (var i = 0; i < vm.number; i++) {
							console.log(i);
							this.post();
						}
					},
					msg : function(str){
						vm.msgList.unshift(str);
					},
					post : function() {
						//发送 post 请求
						this.$http.post(vm.url, JSON.parse(vm.text)).then(function(res) {
							console.log(res);
							fn.msg(res.bodyText);
						}, function(res) {
							console.log(res.status);
						});
					},
		            get : function(){
						this.$http.get(vm.url + vm.text).then(function(res){
							console.log(res);
							fn.msg(res.bodyText);
						},function(res){
						    console.log(res.status);
						});
		            }

				};
			var text = `
{
	type:"find",
	tableName:"account"
}
			`;
			var vm = new Vue({
				el : '#box',
				data : {
					number : 1,
					msgList : [],
					text : text,
					overallData : '',
					service : 'http://127.0.0.1:8080',
					url: '#(d.actionKey[0])',
					openid : 'oTOO8v3ixn5HgygcklNVLz_nK8OE',
					sessionId : '',
				},
				methods : fn
			});
			/*vm.$http.post(vm.service + '/mini/app/api/login', {openid: vm.openid}).then(function(res) {
				console.log(res);
				vm.sessionId = res.data.sessionId;
			}, function(res) {
				console.log(res.status);
			});*/
		}
	</script>
</body>
</html>